"""
这是数据容器章节的综合案例
list的遍历的练习
"""


def for_function(mylist, newlist):
    for item in mylist:
        if item % 2 == 0:
            newlist.append(item)
    return newlist


def while_function(mylist,newlist):
    index = 0
    while index < len((mylist)):
        if mylist[index] % 2 == 0:
            newlist.append(mylist[index])
        index += 1

def list_traverse():
    mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    newlist = []
    for_function(mylist, newlist)
    print(f'通过for循环遍历得到的结果{newlist}')

    newlist.clear()

    while_function(mylist, newlist)
    print(f'通过while循环遍历得到的结果{newlist}')


if __name__ == '__main__':
    list_traverse()